package it.unisalento.appsalento.activity.fragment;

import it.unisalento.R;
import it.unisalento.appsalento.activity.App;
import it.unisalento.appsalento.adapter.AppelliCalendarioAdapter;
import it.unisalento.appsalento.constants.Constants;
import it.unisalento.appsalento.model.Appello;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
//import it.unisalento.appsalento.adapter.EsamiAdapter;

/**
 * Fragment che contiene la lista degli esami sostenuti e da sostenere
 */
public class GiornoCalendarioFragment extends Fragment {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		View rootView = inflater.inflate(R.layout.fragment_giorno_calendario, container,false);
		ListView listView = (ListView) rootView.findViewById(R.id.list_view_appello);

		AppelliCalendarioAdapter adapter = new AppelliCalendarioAdapter(getActivity(), R.layout.row_appello_calendario, App.appelliForDay);
			adapter.notifyDataSetChanged();
			listView.setAdapter(adapter);
			listView.setOnItemClickListener(new OnItemClickListener() {
				public void onItemClick(AdapterView<?> parent, View v,
						int position, long id) {
					Appello appello = (Appello) parent.getItemAtPosition(position);

					Intent intent = new Intent(Constants.SHOW_APPELLO_EVENT);
					intent.putExtra(Constants.APPELLO_ID_NAME, appello.getIdAppello());
					
					LocalBroadcastManager.getInstance(
						getActivity().getApplicationContext()).sendBroadcast(
						intent);
				}

			
			});
		return rootView;
	}
	
	
	

}
